package com.jeecms.wicool.manager.material.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeecms.common.hibernate3.Updater;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.material.WeixinMaterialDetailDao;
import com.jeecms.wicool.entity.material.WeixinMaterial;
import com.jeecms.wicool.entity.material.WeixinMaterialDetail;
import com.jeecms.wicool.manager.material.WeixinMaterialDetailMng;
import com.jeecms.wicool.manager.material.WeixinMaterialMng;

@Service
@Transactional
public class WeixinMaterialDetailMngImpl implements WeixinMaterialDetailMng {
	
	private WeixinMaterialDetailDao dao;
	@Autowired
	public void setDao(WeixinMaterialDetailDao dao) {
		this.dao = dao;
	}
	
	@Transactional(readOnly = true)
	public Pagination getPage(Integer weixinMaterialId,String title ,int pageNo, int pageSize) {
		Pagination page = dao.getPage(weixinMaterialId, title, pageNo, pageSize);
		return page;
	}
	@Override
	public WeixinMaterialDetail findById(Integer id) {
		WeixinMaterialDetail entity = dao.findById(id);
		return entity;
	}
	@Override
	public WeixinMaterialDetail update(WeixinMaterialDetail bean,Integer materialId) {
		WeixinMaterial wm= materialMng.findById(materialId);
		bean.setWeixinMaterial(wm);
		Updater<WeixinMaterialDetail> updater = new Updater<WeixinMaterialDetail>(bean);
		bean = dao.updateByUpdater(updater);
		return bean;
	}
	
	@Override
	public WeixinMaterialDetail save(WeixinMaterialDetail bean,Integer materialId) {
		
		WeixinMaterial wm= materialMng.findById(materialId);
		bean.setWeixinMaterial(wm);
		dao.save(bean);
		return bean;
	}

	@Override
	public WeixinMaterialDetail deleteById(Integer id) {
		WeixinMaterialDetail bean = dao.deleteById(id);
		return bean;
	}
	@Override
	public WeixinMaterialDetail[] deleteByIds(Integer[] ids) {
		WeixinMaterialDetail[] beans = new WeixinMaterialDetail[ids.length];
		for (int i = 0,len = ids.length; i < len; i++) {
			beans[i] = deleteById(ids[i]);
		}
		return beans;
	}
	@Override
	public List<WeixinMaterialDetail> getListWeixinMaterialDetailByPId(Integer pId) {
		// TODO Auto-generated method stub
		return dao.getListWeixinMaterialDetailByPId(pId);
	}
	@Autowired
	private WeixinMaterialMng materialMng;
	
}